package com.edfu.core.commons.service.ws;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.edfu.core.commons.beans.Category;
import com.edfu.core.commons.service.api.IInterestsMgtService;
import com.edfu.core.identitymgt.vo.User;

@Path("/")
@Produces( { MediaType.APPLICATION_JSON })
@Consumes(MediaType.APPLICATION_XML)
@WebService(targetNamespace = "http://com.edfu.core.commons.service.ws.InterestsMgtService")
public class InterestsMgtServiceDelegate {
	
	private static Logger logger = LoggerFactory.getLogger(InterestsMgtServiceDelegate.class);
	
	@Autowired
	private IInterestsMgtService interestsMgtService;

	@POST
	@Path("/interests/user/{userId}/category/{categoryName}")
	@WebMethod(operationName = "addInterests")
	public Response addInterests(@PathParam(value = "userId") String userId, @PathParam(value = "categoryName") String categoryName) {
		logger.debug("Adding interests for the user " + userId + " and for the Category " + categoryName);
		interestsMgtService.addInterests(userId, categoryName);
		
		return Response.ok().build();
	}

	public Response addInterests(String userId, List<String> categoryNames) {
		// TODO Auto-generated method stub
		return Response.ok().build();
	}

	@GET
	@Path("/interests/user/{userId}")
	@WebMethod(operationName = "getUserInterests")
	public Response getUserInterests(@PathParam(value = "userId") String userId) {
		List<Category> categories = interestsMgtService.getUserInterests(userId);
		
		return Response.ok(categories).build();
	}

	@GET
	@Path("/interests/category/{categoryName}")
	@WebMethod(operationName = "getUsersInterestedInCategory")
	public Response getUsersInterestedInCategory(@PathParam(value = "categoryName") String categoryName) {
		List<User> users = interestsMgtService.getUsersInterestedInCategory(categoryName);
		
		return Response.ok(users).build();
	}

}
